import request from "@/utils/request.ts";
import {
  RoleListResponseType,
  UserAssignRoleParamsType,
  UserListResponseType,
  UserType,
} from "@/api/acl/user/type.ts";

enum API {
  // /admin/acl/user/{page}/{limit}
  USER_LIST = "/admin/acl/user/",
  // /admin/acl/user/save
  USER_SAVE = "/admin/acl/user/save",
  // /admin/acl/user/update
  USER_UPDATE = "/admin/acl/user/update",
  // GET /admin/acl/role/get/{id} 获取用户的角色列表
  USER_ROLE_LIST = "/admin/acl/user/toAssign/",
  // /admin/acl/user/doAssignRole post 保存用户角色
  USER_ASSIGN_ROLE = "/admin/acl/user/doAssignRole",
  // /admin/acl/user/batchRemove delete 批量删除用户
  USER_BATCH_REMOVE = "/admin/acl/user/batchRemove/",
}

// 获取用户列表
export const reqUserList = (page: number, limit: number, username: string) =>
  request.get<any, UserListResponseType>(
    API.USER_LIST + `${page}/${limit}/?username=${username}`,
  );

// 新增用户
export const reqUserSave = (data: UserType) =>
  request.post<any, any>(API.USER_SAVE, data);

// 修改用户
export const reqUserUpdate = (data: UserType) =>
  request.put<any, any>(API.USER_UPDATE, data);

// 获取用户角色列表
export const reqUserRoleList = (id: string | number) =>
  request.get<any, RoleListResponseType>(API.USER_ROLE_LIST + `${id}`);

// 保存用户角色
export const reqUserAssignRole = (data: UserAssignRoleParamsType) =>
  request.post<any, any>(API.USER_ASSIGN_ROLE, data);

// 批量删除用户
export const reqUserBatchRemove = (idList: number[]) =>
  request.delete<any, any>(API.USER_BATCH_REMOVE, {
    data: idList,
  });
